<?php
$wid = $_GET['wid'];
require_once 'classes/work.class.php';
require_once 'classes/category.class.php';
$work = new Work($wid);
$category = new Category($work->getCategoryId());
?>

<h2>Feedbacks</h2>
<p><strong><?php echo $category->getName(); ?></strong></p>
<blockquote style="border:0;padding-left: 0">
    <p><?php echo $work->getDescription(); ?></p>
    <small>Work description</small>
</blockquote>
<?php
$sql = "SELECT DISTINCT `feedbacks`.`id`, `feedbacks`.`workid`,`comment`,`feedbacks`.`uid`, AVG(`speed`) AS `speed`, AVG(`quality`) AS `quality` FROM `feedbacks` INNER JOIN `works` ON `works`.`id`=`feedbacks`.`workid` WHERE `works`.`id` = '$wid'";
$query = $db->query($sql);
$res = $db->fetch($query);
?>
<h3>Average ratings</h3>
<?php
         $both = ($res->quality + $res->speed) / 2;
         $q = $res->quality;
         $s = $res->speed; ?>       

<table cellpadding="0" cellspacing="0" style="width:220px;">
    <tr style="height:30px">
        <td style="padding:5px 3px 3px 6px;margin:0">
            Both 
        </td>
        <td style="padding:5px 3px 3px 6px;;margin:0">
            <?php
            for ($c = 0; $c < $both; $c++)
                echo "<img style='width:16px;' src='star_48.png'/>";
            $c = 0;
            ?>
        </td>
    </tr>
    <tr style="height:30px">
        <td style="padding:5px 3px 3px 6px;margin:0;width: 100px">Speed/On Time</td>
        <td style="padding:5px 3px 3px 6px;;margin:0">
            <?php
            for ($c = 0; $c < $s; $c++)
                echo "<img style='width:16px;' src='star_48.png'/>";
            $c = 0;
            $s = 0;
            ?>
        </td>
    </tr>
    <tr style="height:30px">
        <td style="padding:5px 3px 3px 6px;margin:0">
            Quality 
        </td>
        <td style="padding:5px 3px 3px 6px;;margin:0">
            <?php
            for ($c = 0; $c < $q; $c++)
                echo "<img style='width:16px;' src='star_48.png'/>";
            $c = 0;
            $q = 0;
            ?>
        </td>
    </tr>
</table>

<?php
$sql = "SELECT `feedbacks`.`comment`, `feedbacks`.`workid` FROM `feedbacks` INNER JOIN `works` ON `works`.`id`=`feedbacks`.`workid` WHERE `works`.`id` = '$wid'";
$query = $db->query($sql) or die(mysql_error());

while ($row = $db->fetch($query)) {
    if (!empty($row->comment)) {
    ?>
<blockquote>
    <p><i><?php echo $row->comment; ?></i></p>
    <small>Feedback comment</small>
</blockquote>

<?php
    }
}
?>